package pl.edu.agh.bd2.servlets;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import pl.edu.agh.bd2.domain.*;
import pl.edu.agh.bd2.util.HibernateDAO;

/**
 * Servlet implementation class NewTeacherServlet
 */
@WebServlet("/newTeacher.do")
public class NewTeacherServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NewTeacherServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		HibernateDAO<Teacher> dao = new HibernateDAO<Teacher>();
		HibernateDAO<Subject> dao2 = new HibernateDAO<Subject>();
		HibernateDAO<Student> daoStudent = new HibernateDAO<Student>();
		
		Teacher teacher = new Teacher(request.getParameter("login"),request.getParameter("password"),"TEACHER", 
				request.getParameter("contactEMail"),request.getParameter("phoneNumber"),request.getParameter("name"),
				request.getParameter("surname"),request.getParameter("address"),request.getParameter("title"),new HashSet<Subject>());
		
		Subject subject1 = new Subject("przedmiot1", new HashSet<GradeType>(),new HashSet<Student>(), teacher, new HashSet<Topic>());
		Subject subject2 = new Subject("przedmiot2", new HashSet<GradeType>(),new HashSet<Student>(), teacher, new HashSet<Topic>());
		
//		teacher.addSubject(subject1);
//		teacher.addSubject(subject2);
//		GradeType gt1 = new GradeType("gradetype", );
//		
//		Grade g1 = new Grade(2.5, new Date, )
//		
//		Set<Subject> subjectSet1 = new HashSet<Subject>();
//		subjectSet1.add(subject1);
//		subjectSet1.add(subject2);
		
//		subjectSet1.add(subject1);
//		subjectSet1.add(subject2);
//		
//		Set<Grade> gradeSet1 = new HashSet<Grade>();
//		gradeSet1.add
		
//		Student s1 = new Student("s1", "s1sur","adres","phone",subjectSet1,gradeSet1);
//		Student s2 = new Student("s2", "s1sur","adres","phone",subjectSet1,gradeSet1);
//		Student s3 = new Student("s3", "s1sur","adres","phone",subjectSet1,gradeSet1);

//		subject1.addStudent(s1);
//		subject1.addStudent(s2);
//		subject1.addStudent(s3);
		
//		subject2.addStudent(s1);
//		subject2.addStudent(s2);
//		subject2.addStudent(s3);
		
		dao.persist(teacher);
		dao2.persist(subject1);
		dao2.persist(subject2);
//		daoStudent.persist(s1);
//		daoStudent.persist(s2);
//		daoStudent.persist(s3);
		
		RequestDispatcher view = request.getRequestDispatcher("/registerManagement.jsp");
		view.forward(request, response);
	}

}
